<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>获取汉字首字母 js 插件使用</title>
</head>
<body>
  <div>
    <div>获取字符串第一个字符的首字母</div></div>
    <input type="text" onblur="getInitial1(this.value)">
    <button>获取首字母</button>
    <div id="txt1"></div>
    <div style="font-size: 12px; color: #999; margin-top: 20px;">多个字母开头的多音字会显示多个字母</div>
  </div>
  <div>
    <div>获取字符串每个字符的首字母</div></div>
    <input type="text" onblur="getInitial2(this.value)">
    <button>获取首字母</button>
    <div id="txt2"></div>
    <div style="font-size: 12px; color: #999; margin-top: 20px;">多个字母开头的多音字会显示多个字母</div>
  </div>
  <div>
    <div>获取字符串拼音</div></div>
    <input type="text" onblur="getInitial3(this.value)">
    <button>获取首字母</button>
    <div id="txt3"></div>
    <div style="font-size: 12px; color: #999; margin-top: 20px;">多个字母开头的多音字会显示多个字母</div>
  </div>

  <script src="./convert-pinyin.js"></script>
  <script>
    // 返回所有字符的首字母
    function getInitial1(str) {
      let py = getChineseStrPY(str);
      console.log(py);
      document.getElementById('txt1').textContent = py;
    }
    function getInitial2(str) {
      // 返回第一个字符的首字母
      let py = getChineseStrPY(str, 'first');
      console.log(py);
      document.getElementById('txt2').textContent = py;
    }
    // 返回每一个字符的拼音全拼
    function getInitial3(str) {
      let py = getChineseStrPY(str, 'all');
      console.log(py);
      document.getElementById('txt3').textContent = py;
    }
  </script>
</body>
</html>